package net.xdclass.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.xdclass.request.LockProductRequest;
import net.xdclass.service.ProductService;
import net.xdclass.util.JsonData;
import net.xdclass.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 二当家小D
 * @since 2021-06-02
 */
@Api(tags = "商品模块")
@RestController
@RequestMapping("/api/product/v1")
public class ProductController {
    @Autowired
    private ProductService productService;

    @ApiOperation("商品列表分页查询")
    @GetMapping("page")
    public JsonData page(@RequestParam(value = "page" , defaultValue = "1") int page,
                         @RequestParam(value = "size", defaultValue = "10") int size){
        Map<String, Object> pageInfo = productService.page(page, size);
        return JsonData.buildSuccess(pageInfo);
    }

    @ApiOperation("商品列表分页查询")
    @GetMapping("detail/{product_id}")
    public JsonData page(@PathVariable("product_id") long productId) {

        ProductVO productVO = productService.detail(productId);
        return JsonData.buildSuccess(productVO);
    }

    @PostMapping("lock_products")
    public JsonData lockProducts(@RequestBody LockProductRequest lockProductRequest) {
        JsonData jsonData = productService.lockProducts(lockProductRequest);
        return jsonData;
    }
}

